package com.bootdo.common.utils;

import java.math.BigDecimal;
import java.util.UUID;

public class UploadUtils {

    /**
     * 根据文件大小处理展示数据
     * @param fileSzie
     * @return
     */
    public static String getFileSizePatter(long fileSzie){
        String fileSizePatter = "";
        if(fileSzie == 0) {
            fileSizePatter = "--";
        }else if(fileSzie > 0 && fileSzie < 1024) {
            fileSizePatter = String.valueOf(fileSzie) + "B";
        }else if(fileSzie > 1024 && fileSzie < 1024 * 1024) {
            double fileSizeFor = new BigDecimal((float)fileSzie/1024).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            fileSizePatter = String.valueOf(fileSizeFor) + "KB";
        }else {
            double fileSizeFor = new BigDecimal((float)fileSzie/(1024 * 1024)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            fileSizePatter = String.valueOf(fileSizeFor) + "M";
        }
        return fileSizePatter;
    }

}
